from faker import Faker
faker1 = Faker(locale='zh_cn')
import json
#编写一个学生方法，产生一堆学生对象（姓名），传入形参控制学生生成数量
"""
def student_name(a):
    for i in a:
        print(faker1.name())
student_name(range(5))
"""
#创建一个方法，用来生成普通人必备的信息：姓名、年龄、住址、身份证号、手机号，随机生成20个写入personinfo.txt里格式：姓名：xxx  年龄：xxx 住址：xxx 身份证号：xxx
"""
for i in range(20):
            name=faker1.name()
            age=faker1.random.randint(1,100)
            address=faker1.address()
            shenfenzhenghao=faker1.ssn(min_age=18,max_age=90)
            phone=faker1.phone_number()
            with open('personinfo.txt',mode='a',encoding='utf-8') as f:
                f.write(f"姓名：{name},年龄：{age},住址：{address},身份证号：{shenfenzhenghao},手机号：{phone}\n")
"""
#文本 student.txt中包含下面的内容
"""
data = {
    'zhangsan':30,
    'lisi':50,
    'wangwu':60,
    'lifei':70
}
with open("student.txt",'r') as f:
    print(json.load(f))
"""
#给你一个 非空 整数数组 nums ，除了某个元素只出现一次以外，其余每个元素均出现两次。找出那个只出现了一次的元素
"""
nums = [1999,2,2,3,3,4,4,5,5]
for i in nums:
    if nums.count(i) == 1:
        print(i)

"""

#输入：["1","a","b","3","5","8","_"] 想要提取里面得数字，并保存到一个列表中
"""
list1 =["1","a","b","3","5","8","_"]
list2 = []
for i in list1:
    if i > "0" and i < "9":
        print(i)
        list2.append(i)
print(list2)
"""
#写函数,函数接收的4个参数分别是:姓名,性别(默认为男),年龄,地址用户通过input输入这4个内容(支持持续输入,Q或q退出),并传递给函数函数接收到这些内容,将其追加到student_msg文件中
"""
def personal_information():
    sex = '男'
    while 1:
        name = input("请输入姓名：")
        if name == "q" or name == "Q":
            break
        sex = input("请输入性别：")
        if sex == "q" or name == "Q":
            break
        age = input("请输入年龄：")
        if age == "q" or name == "Q":
            break
        address = input("请输入地址")
        if address == "q" or name == "Q":
            break
        print(name,sex,age,address)
        with open("student_msg.txt","w") as f:
            f.write(f'{name},{sex},{age},{address}')
personal_information()
"""
#每次对学生管理系统发生改动，要写入改动点到log.txt文本中
"""
list1 = []
def zhengjia():
    shuru = input("输入要添加的学生姓名：")
    if shuru not in list1:
        list1.append(shuru)
        print("添加成功")
        with open('log.txt', mode='a', encoding='utf-8') as f:
            f.write(f"添加了一名学生，学生为{shuru}")
    else:
        print("添加失败")

def shanchu():
    shuru = input("要删除的学生姓名：")
    if shuru in list1:
        list1.remove(shuru)
        print("删除成功")
        with open('log.txt', mode='a', encoding='utf-8') as f:
            f.write(f"删除了一名学生，学生为{shuru}")
    else:
        print("删除失败，不存在该学生")
def xiugai():
    cunzai = input("要修改的学生姓名：")
    shuru = input("修改hou的学生姓名：")
    if cunzai in list1:
        for i in range(len(list1)):
            if list[i] == cunzai:
                list[i] = shuru
    else:
        print("没有该学生，请确定要修改的学生姓名")
    with open('log.txt', mode='a', encoding='utf-8') as f:
        f.write(f"修改了一名学生，学生为{cunzai}，修改后学生名为{shuru}")
def chaxun():
    for i in range(len(list1)):
        print(f"第{i + 1}的学生姓名为{list1[i]}")
        with open('log.txt', mode='a', encoding='utf-8') as f:
            f.write("显示所有学生的信息")

while 1:
    print("学生管理系统")
    print("1.添加学生信息")
    print("2.删除学生信息")
    print("3.修改学生信息")
    print("4.显示所有学生信息")
    print("0.退出系统")
    shuru = input("输入对应的编号")
    if shuru == "1":
        zhengjia()
    elif shuru == "2":
        shanchu()
    elif shuru == "3":
        xiugai()
    elif shuru == "4":
        chaxun()
    elif shuru == "0":
        break
"""
#简单的好友管理系统的功能菜单（存入文件）
list1 = []
while 1:
    print("欢迎来到好友管理系统!")
    print("请输入你的选项")
    print("1.添加好友")
    print("2.删除好友")
    print("3.备注好友")
    print("4.展示好友")
    print("5.关闭好友管理系统")
    xuanxiang = input("请输入你的选项：")
    if xuanxiang == "1":
        haoyou = input("请输入要添加的好友：")
        if haoyou not in list1:
            list1.append(haoyou)
            print("好友添加成功")
            with open("haoyou.txt", "a") as f:
                f.write(f"添加好友为{haoyou}\n")
        else:
            print("添加失败")
    elif xuanxiang == "2":
        shanchu = input("请输入删除好友姓名：")
        if shanchu in list1:
            list1.remove(shanchu)
            print("删除成功")
            with open("haoyou.txt", "a") as f:
                f.write(f"删除好友姓名为{shanchu}\n")
        else:
            print("删除失败")
    elif xuanxiang == "3":
        biezhu = input("请输入要修改的好友姓名：")
        xiugaibeizhu = input("请输入修改后的好友姓名：")
        if biezhu in list1:
            for i in range(len(list1)):
                if list[i] == biezhu:
                    list[i] = xiugaibeizhu
                    print("备注成功")
                    with open("haoyou.txt", "a") as f:
                        f.write(f"将{biezhu}好友的备注改为{xiugaibeizhu}\n")
                else:
                    print("备注失败")
    elif xuanxiang == "4":
        for i in range(len(list1)):
            if i == "null":
                print("好友列表为空")
            else:
                print(f"第{i + 1}的好友为{list1[i]}")
            with open('haoyou.txt', 'a') as f:
                f.write("展示好友\n")
    elif xuanxiang == "5":
        print("关闭管理系统")
        break
